package com.freeheart.validation.constraintvalidators.recent;


import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

/**
 * 针对{@code java.time.LocalDate}类型的，计算距离今天的时间差
 *
 * @author: EmperorHeart
 * @date: 2025/5/10 1:31
 * @description
 */
public class ComputeGapForLocalDate implements ComputeGap {

    @Override
    public boolean support(Object obj) {
        return obj instanceof LocalDate;
    }

    @Override
    public long compute(Object obj, RecentProperties rp) {
        LocalDate dt = (LocalDate) obj;
        // 对于LocalDate不管你truncate都灭有效果的：只能计算天
        return ChronoUnit.DAYS.between(dt, LocalDate.now());
    }
}
